<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Explore API | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'graph-explore-api.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/graph-explore-api.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/graph-explore-api.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/graph-explore-api.html" rel="nofollow" target="_blank">../en/graph-explore-api.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-node">Explore API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="enrich-stats-api.html">« Enrich stats API</a>
</span>
<span class="next">
<a href="indices.html">Index APIs »</a>
</span>
</div>
<div class="chapter xpack">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="graph-explore-api"></a>Explore API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a><a class="xpack_tag" href="https://www.elastic.co/subscriptions"></a>
</h2>
</div></div></div>
<p>The Graph explore API enables you to extract and summarize information about
the documents and terms in your Elasticsearch index.</p>
<p>The easiest way to understand the behaviour of this API is to use the
Graph UI to explore connections. You can view the most recent request submitted
to the <code class="literal">_explore</code> endpoint from the <span class="strong strong"><strong>Last request</strong></span> panel. For more information,
see <a href="https://www.elastic.co/guide/en/kibana/7.7/graph-getting-started.html" class="ulink" target="_top">Getting Started with Graph</a>.</p>
<p>For additional information about working with the explore API, see the Graph
<a href="https://www.elastic.co/guide/en/kibana/7.7/graph-troubleshooting.html" class="ulink" target="_top">Troubleshooting</a> and
<a href="https://www.elastic.co/guide/en/kibana/7.7/graph-limitations.html" class="ulink" target="_top">Limitations</a> topics.</p>
<h3>
<a id="_request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h3>
<p><code class="literal">POST &lt;index&gt;/_graph/explore</code></p>
<h3>
<a id="_description_11"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h3>
<p>An initial request to the <code class="literal">_explore</code> API contains a seed query that identifies
the documents of interest and specifies the fields that define the vertices
and connections you want to include in the graph. Subsequent <code class="literal">_explore</code> requests
enable you to <em>spider out</em> from one more vertices of interest. You can exclude
vertices that have already been returned.</p>
<h3>
<a id="_request_body"></a>Request Body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h3>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
query
</span>
</dt>
<dd>
<p>
A seed query that identifies the documents of interest. Can be any valid
Elasticsearch query. For example:
</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"query": {
  "bool": {
    "must": {
      "match": {
        "query.raw": "midi"
      }
    },
    "filter": [
      {
        "range": {
          "query_time": {
            "gte": "2015-10-01 00:00:00"
          }
        }
      }
    ]
  }
}</pre>
</div>
</dd>
<dt>
<span class="term">
vertices
</span>
</dt>
<dd>
<p>
Specifies or more fields that contain the terms you want to include in the
graph as vertices. For example:
</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"vertices": [
  {
    "field": "product"
    }
]</pre>
</div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
field
</span>
</dt>
<dd>
Identifies a field in the documents of interest.
</dd>
<dt>
<span class="term">
include
</span>
</dt>
<dd>
Identifies the terms of interest that form the starting points
from which you want to spider out. You do not have to specify a seed query
if you specify an include clause. The include clause implicitly querys for
documents that contain any of the listed terms listed.
In addition to specifying a simple array of strings, you can also pass
objects with <code class="literal">term</code> and <code class="literal">boost</code> values to boost matches on particular terms.
</dd>
<dt>
<span class="term">
exclude
</span>
</dt>
<dd>
The <code class="literal">exclude</code> clause prevents the specified terms from being included in
the results.
</dd>
<dt>
<span class="term">
size
</span>
</dt>
<dd>
Specifies the maximum number of vertex terms returned for each
field. Defaults to 5.
</dd>
<dt>
<span class="term">
min_doc_count
</span>
</dt>
<dd>
Specifies how many documents must contain a pair of terms before it is
considered to be a useful connection. This setting acts as a certainty
threshold. Defaults to 3.
</dd>
<dt>
<span class="term">
shard_min_doc_count
</span>
</dt>
<dd>
This advanced setting controls how many documents on a particular shard have
to contain a pair of terms before the connection is returned for global
consideration. Defaults to 2.
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
connections
</span>
</dt>
<dd>
<p>
Specifies or more fields from which you want to extract terms that are
associated with the specified vertices. For example:
</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"connections": {  <a id="CO559-1"></a><i class="conum" data-value="3"></i>
  "vertices": [
    {
      "field": "query.raw"
    }
  ]
}</pre>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>Connections can be nested inside the <code class="literal">connections</code> object to
explore additional relationships in the data. Each level of nesting is
considered a <em>hop</em>, and proximity within the graph is often described in
terms of <em>hop depth</em>.</p>
</div>
</div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
query
</span>
</dt>
<dd>
An optional <em>guiding query</em> that constrains the Graph API as it
explores connected terms. For example, you might want to direct the Graph
API to ignore older data by specifying a query that identifies recent
documents.
</dd>
<dt>
<span class="term">
vertices
</span>
</dt>
<dd>
<p>
Contains the fields you are interested in. For example:
</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"vertices": [
  {
    "field": "query.raw",
    "size": 5,
    "min_doc_count": 10,
    "shard_min_doc_count": 3
  }
]</pre>
</div>
</dd>
</dl>
</div>
</dd>
<dt>
<span class="term">
controls
</span>
</dt>
<dd>
<p>
Direct the Graph API how to build the graph.
</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
use_significance
</span>
</dt>
<dd>
The <code class="literal">use_significance</code> flag filters associated terms so only those that are
significantly associated with your query are included. For information about
the algorithm used to calculate significance, see the
<a href="search-aggregations-bucket-significantterms-aggregation.html" class="ulink" target="_top">significant_terms
aggregation</a>. Defaults to <code class="literal">true</code>.
</dd>
<dt>
<span class="term">
sample_size
</span>
</dt>
<dd>
Each <em>hop</em> considers a sample of the best-matching documents on each
shard. Using samples improves the speed of execution and keeps
exploration focused on meaningfully-connected terms. Very small values
(less than 50) might not provide sufficient weight-of-evidence to identify
significant connections between terms. Very large sample sizes can dilute
the quality of the results and increase execution times.
Defaults to 100 documents.
</dd>
<dt>
<span class="term">
timeout
</span>
</dt>
<dd>
The length of time in milliseconds after which exploration will be halted
and the results gathered so far are returned. This timeout is honored on
a best-effort basis. Execution might overrun this timeout if, for example,
a long pause is encountered while FieldData is loaded for a field.
</dd>
<dt>
<span class="term">
sample_diversity
</span>
</dt>
<dd>
<p>
To avoid the top-matching documents sample being dominated by a single
source of results, it is sometimes necessary to request diversity in
the sample. You can do this by selecting a single-value field and setting
a maximum number of documents per value for that field. For example:
</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">"sample_diversity": {
  "field": "category.raw",
  "max_docs_per_value": 500
}</pre>
</div>
</dd>
</dl>
</div>
</dd>
</dl>
</div>
<h3>
<a id="_examples_14"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h3>
<h4>
<a id="basic-search"></a>Basic exploration<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h4>
<p>An initial search typically begins with a query to identify strongly related terms.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST clicklogs/_graph/explore
{
    "query": { <a id="CO559-2"></a><i class="conum" data-value="1"></i>
        "match": {
            "query.raw": "midi"
        }
    },
    "vertices": [ <a id="CO559-3"></a><i class="conum" data-value="2"></i>
        {
            "field": "product"
        }
    ],
    "connections": {  <a id="CO559-4"></a><i class="conum" data-value="3"></i>
        "vertices": [
            {
                "field": "query.raw"
            }
        ]
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1587.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO559-2"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Seed the exploration with a query. This example is searching
clicklogs for people who searched for the term "midi".</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO559-3"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Identify the vertices to include in the graph. This example is looking for
product codes that are significantly associated with searches for "midi".</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO559-1"><i class="conum" data-value="3"></i></a><a href="#CO559-4"></a></p>
</td>
<td align="left" valign="top">
<p>Find the connections. This example is looking for other search
terms that led people to click on the products that are associated with
searches for "midi".</p>
</td>
</tr>
</table>
</div>
<p>The response from the explore API looks like this:</p>
<div class="pre_wrapper lang-js">
<pre class="programlisting prettyprint lang-js">{
   "took": 0,
   "timed_out": false,
   "failures": [],
   "vertices": [ <a id="CO560-1"></a><i class="conum" data-value="1"></i>
      {
         "field": "query.raw",
         "term": "midi cable",
         "weight": 0.08745858139552132,
         "depth": 1
      },
      {
         "field": "product",
         "term": "8567446",
         "weight": 0.13247784285434397,
         "depth": 0
      },
      {
         "field": "product",
         "term": "1112375",
         "weight": 0.018600718471158982,
         "depth": 0
      },
      {
         "field": "query.raw",
         "term": "midi keyboard",
         "weight": 0.04802242866755111,
         "depth": 1
      }
   ],
   "connections": [ <a id="CO560-2"></a><i class="conum" data-value="2"></i>
      {
         "source": 0,
         "target": 1,
         "weight": 0.04802242866755111,
         "doc_count": 13
      },
      {
         "source": 2,
         "target": 3,
         "weight": 0.08120623870976627,
         "doc_count": 23
      }
   ]
}</pre>
</div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO560-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>An array of all of the vertices that were discovered. A vertex is an indexed
term, so the field and term value are provided. The <code class="literal">weight</code> attribute specifies
a significance score. The <code class="literal">depth</code> attribute specifies the hop-level at which
the term was first encountered.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO560-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The connections between the vertices in the array. The <code class="literal">source</code> and <code class="literal">target</code>
properties are indexed into the vertices array and indicate which vertex term led
to the other as part of exploration. The <code class="literal">doc_count</code> value indicates how many
documents in the sample set contain this pairing of terms (this is
not a global count for all documents in the index).</p>
</td>
</tr>
</table>
</div>
<h4>
<a id="optional-controls"></a>Optional controls<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h4>
<p>The default settings are configured to remove noisy data and
get the "big picture" from your data. This example shows how to specify
additional parameters to influence how the graph is built.</p>
<p>For tips on tuning the settings for more detailed forensic evaluation where
every document could be of interest, see the
<a href="https://www.elastic.co/guide/en/kibana/7.7/graph-troubleshooting.html" class="ulink" target="_top">Troubleshooting</a> guide.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST clicklogs/_graph/explore
{
    "query": {
        "match": {
            "query.raw": "midi"
        }
    },
   "controls": {
      "use_significance": false,<a id="CO561-1"></a><i class="conum" data-value="1"></i>
      "sample_size": 2000,<a id="CO561-2"></a><i class="conum" data-value="2"></i>
      "timeout": 2000,<a id="CO561-3"></a><i class="conum" data-value="3"></i>
      "sample_diversity": {<a id="CO561-4"></a><i class="conum" data-value="4"></i>
         "field": "category.raw",
         "max_docs_per_value": 500
      }
   },
   "vertices": [
      {
         "field": "product",
         "size": 5,<a id="CO561-5"></a><i class="conum" data-value="5"></i>
         "min_doc_count": 10,<a id="CO561-6"></a><i class="conum" data-value="6"></i>
         "shard_min_doc_count": 3<a id="CO561-7"></a><i class="conum" data-value="7"></i>
      }
   ],
   "connections": {
      "query": {<a id="CO561-8"></a><i class="conum" data-value="8"></i>
         "bool": {
            "filter": [
               {
                  "range": {
                     "query_time": {
                        "gte": "2015-10-01 00:00:00"
                     }
                  }
               }
            ]
         }
      },
      "vertices": [
         {
            "field": "query.raw",
            "size": 5,
            "min_doc_count": 10,
            "shard_min_doc_count": 3
         }
      ]
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1588.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Disable <code class="literal">use_significance</code> to include all associated terms, not just the
ones that are significantly associated with the query.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>Increase the sample size to consider a larger set of documents on
each shard.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>Limit how long a graph request runs before returning results.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-4"><i class="conum" data-value="4"></i></a></p>
</td>
<td align="left" valign="top">
<p>Ensure diversity in the sample by setting a limit on the number of documents
per value in a particular single-value field, such as a category field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-5"><i class="conum" data-value="5"></i></a></p>
</td>
<td align="left" valign="top">
<p>Control the maximum number of vertex terms returned for each field.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-6"><i class="conum" data-value="6"></i></a></p>
</td>
<td align="left" valign="top">
<p>Set a certainty threshold that specifies how many documents have to contain
a pair of terms before we consider it to be a useful connection.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-7"><i class="conum" data-value="7"></i></a></p>
</td>
<td align="left" valign="top">
<p>Specify how many documents on a shard have to contain a pair of terms before
the connection is returned for global consideration.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO561-8"><i class="conum" data-value="8"></i></a></p>
</td>
<td align="left" valign="top">
<p>Restrict which document are considered as you explore connected terms.</p>
</td>
</tr>
</table>
</div>
<h4>
<a id="spider-search"></a>Spidering operations<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/graph/explore.asciidoc">edit</a>
</h4>
<p>After an initial search, you typically want to select vertices of interest and
see what additional vertices are connected. In graph-speak, this operation is
referred to as "spidering". By submitting a series of requests, you can
progressively build a graph of related information.</p>
<p>To spider out, you need to specify two things:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
The set of vertices for which you want to find additional connections
</li>
<li class="listitem">
The set of vertices you already know about that you want to exclude from the
results of the spidering operation.
</li>
</ul>
</div>
<p>You specify this information using <code class="literal">include`and `exclude</code> clauses. For example,
the following request starts with the product <code class="literal">1854873</code> and spiders
out to find additional search terms associated with that product. The terms
"midi", "midi keyboard", and "synth" are excluded from the results.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">POST clicklogs/_graph/explore
{
   "vertices": [
      {
         "field": "product",
         "include": [ "1854873" ] <a id="CO562-1"></a><i class="conum" data-value="1"></i>
      }
   ],
   "connections": {
      "vertices": [
         {
            "field": "query.raw",
            "exclude": [ <a id="CO562-2"></a><i class="conum" data-value="2"></i>
               "midi keyboard",
               "midi",
               "synth"
            ]
         }
      ]
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1589.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO562-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>The vertices you want to start from are specified
as an array of terms in an <code class="literal">include</code> clause.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO562-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>The <code class="literal">exclude</code> clause prevents terms you already know about from being
included in the results.</p>
</td>
</tr>
</table>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="enrich-stats-api.html">« Enrich stats API</a>
</span>
<span class="next">
<a href="indices.html">Index APIs »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>